Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Sync API Refactor #87

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft

Sync API Refactor #87

wants to merge 19 commits into from

Conversation

helmturner
Copy link
Contributor

PR Checklist

Overview

Refactor sync api to be easier to follow and map nicely with the new async api (wip)

  • use maps/sets for more declarative code
  • rename things
    Change the api for guards to be separate from that of serialize/deserialize type handlers
  • give guards their own configuration, but still run them for any unhandled values

feat: guards are distinct from type handlers
chore: rename some things
types: general type improvements
chore: add more iterable utils
Copy link

vercel bot commented Nov 25, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tupleson-async ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 4, 2024 6:35am

@helmturner helmturner requested a review from KATT November 25, 2023 13:07
feat!: new guard api
Copy link

codecov bot commented Nov 26, 2023

Codecov Report

Attention: 300 lines in your changes are missing coverage. Please review.

Comparison is base (9bf904f) 94.08% compared to head (9aa3dc1) 85.64%.
Report is 1 commits behind head on main.

Files Patch % Lines
src/async/createFoldAsyncFn.ts 0.00% 120 Missing ⚠️
src/async/createUnfoldAsyncFn.ts 0.00% 62 Missing ⚠️
src/iterableTypes.ts 0.00% 33 Missing ⚠️
src/async/serializeAsync2.ts 93.07% 26 Missing and 1 partial ⚠️
src/tsonAssert.ts 0.00% 24 Missing ⚠️
src/async/handlers/tsonPromise2.ts 77.04% 14 Missing ⚠️
src/internals/testUtils.ts 86.36% 12 Missing ⚠️
src/async/iterableUtils.ts 87.50% 4 Missing ⚠️
src/internals/isComplexValue.ts 57.14% 3 Missing ⚠️
src/sync/serialize.ts 98.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #87      +/-   ##
==========================================
- Coverage   94.08%   85.64%   -8.44%     
==========================================
  Files          31       40       +9     
  Lines        1876     2864     +988     
  Branches      194      258      +64     
==========================================
+ Hits         1765     2453     +688     
- Misses        109      407     +298     
- Partials        2        4       +2     
Flag Coverage Δ
unit 85.64% <73.30%> (-8.44%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

<!-- 👋 Hi, thanks for sending a PR to tson! 💖.
Please fill out all fields below and make sure each item is true and [x]
checked.
Otherwise we may not be able to review your PR. -->

## PR Checklist

- [ ] Addresses an existing open issue: fixes #000
- [ ] That issue was marked as [`status: accepting
prs`](https://github.com/trpc/tupleson/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [ ] Steps in
[CONTRIBUTING.md](https://github.com/trpc/tupleson/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

<!-- Description of what is changed and how the code change does that.
-->
@helmturner helmturner changed the title initial new abstraction for sync Sync API Refactor Nov 26, 2023
@helmturner
Copy link
Contributor Author

helmturner commented Jan 4, 2024

I've got the async serializer (mostly) spitting out the expected result. The main feature here is using an iterative algorithm for serialization, rather than a recursive one. There's more to do, but this is illustrative enough to be a PoC.

The benefits I'm hoping to achieve:

  • Better error handling
  • Deep-serialization of of arbitrarily complex values (e.g. Promise<AsyncIterable<Promise<string>>>)
  • Separation from, but interoperability with, the transport layer
  • Separation of concerns between streaming and serializing
  • An API that is easy to customize for your use-case (websocket, http JSON streams, http2/3 SSE streams, etc)
  • AsyncGenerators are a first class-citizen

Todos:

  • Clean up & normalize error handling
  • Change string flags to numbers
  • Improve serialization output of built-ins (e.g. Arrrays, POJOs)
  • Deserialization
  • Lots of cleanup

fix: don't stringify primitives prematurely
tests: improved tests for new async stuff
primitive: "string",
};
} as TsonType<string, string>;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to the other way around. Did you want to use the satisfies operator?

Copy link
Contributor Author

@helmturner helmturner Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is necessary due to the changes in src/sync/syncTypes.ts (sorry for the slow reply!)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants